var request = require('../../utils/request.js')
Page({
  data: {
    postlist:{}
  },
  input:function(e){
    this.data.postlist[e.currentTarget.id]=e.detail.value
  },
  sendData:function(){
    var re= /^1[0-9]{10}$/;
    if(!this.data.postlist.sn){
      my.showToast({
        content: "请填写设备号",
        type:'fail',
        duration: 1000
      })
    } else if(!this.data.postlist.remark){
      my.showToast({
        content: "请填写故障原因",
        type:'fail',
        duration: 1000
      })
    } else if(!re.test(this.data.postlist.link)){
      my.showToast({
        content: "手机格式错误",
        type:'fail',
        duration: 1000
      })
    } else {
      var that=this;
      var success=function(data){
        my.navigateBack({
          success:function(){
            my.showToast({
              content:'操作成功',
              type:'success',
              duration: 1000
            })
          }
        })
      }
      request.postdata('/Index/breakDown',that.data.postlist,success,that)
    }
  },
  onLoad: function () {
    my.getNetworkType({
      success: (res) => {
        if(!res.networkAvailable||res.networkType=='UNKNOWN'){
          my.showToast({
            content: '网络状态不佳，请检查网络',
            type:'fail',
            duration: 2000
          })
        }
      }
    })
  }
})
